class CommondLineTool private constructor(): ICallBack{
    companion object{
        val instance:CommondLineTool by lazy { CommondLineTool() }
    }

    fun start(){
        //创建文件管理器对象
        //并配置 自己 为接收回调结果的对象 所以当前类必须实现ICallBack接口
        val fileManager = FileManager(this)
        val parser = CommondParser(fileManager)
        while (true) {
            //显示提示
            showTitle(fileManager.currentDirectoryName())
            //输入指令
            readCommond().also {
                it?.also { cmd ->
                    //解析指令
                    try {
                        parser.parse( cmd )
                    }catch (e:Exception){
                        e.printStackTrace()
                    }
                }
            }
        }
    }

    private fun readCommond() = readlnOrNull()
    private fun showTitle(str:String){
        print("[$str] # ")
    }

    override fun showInfo(strs: List<String>?, str: String?) {
        strs?.let {
            it.forEach {info ->
                println(info)
            }
        }

        str?.let {
            println(it)
        }
    }

}

fun main() {
    CommondLineTool.instance.start()
}